package xiaolong.zhou.spring_demo.Utils;

import groovy.util.logging.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xiaolong.zhou.spring_demo.Service.achieve.MailService;

import java.util.Map;

@Slf4j
@Component
public class ReceiveRabbitListener {
    @Autowired
    private MailService mailService;
    /**
     * 接受Rabbit消息队列
     * @param data
     */
    @RabbitListener(queues = "recharge-queues")
    public void ListenerRechargeQueues(Map data)
    {
        //发送邮箱消息到邮箱
        String subject = "余额充值成功提醒";
        String emailMsg = "您好:\n"
                + "\n你已成功为账户充值:" + data.get("price")
                +"\n当前余额"+data.get("new_price")
                +"\n感谢你的支持有任何疑问请联系我们\n"
                + "\n(这是一封通过自动发送的邮件，请不要直接回复）";
        System.out.println(emailMsg);
        Boolean endEmailStatus = mailService.sendTextMail((String) data.get("email"),subject,emailMsg);
       System.out.println(endEmailStatus);
    }

}
